//
//  YTExpertTableViewCell.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/11/20.
//

#import "YTExpertTableViewCell.h"

@interface YTExpertTableViewCell ()
@property (nonatomic ,strong) UIImageView * icon;
@property (nonatomic ,strong) UILabel * realName;
@property (nonatomic ,strong) UILabel * institution;
@property (nonatomic ,strong) UILabel * speciality;
@property (nonatomic ,strong) UILabel * callCount;
@property (nonatomic ,strong) UIView * zxview;
@property (nonatomic ,strong) UIView * SQview;
@property (nonatomic ,strong) UILabel * SQLab;
@property (nonatomic ,strong) UIImageView * SQImg;

@end

@implementation YTExpertTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self setupView];
    }
    return self;
}


- (void)setupView{
    
    self.backgroundColor = UIColor.clearColor;
    self.contentView.backgroundColor = UIColor.clearColor;
    self.userInteractionEnabled = YES;
    self.contentView.userInteractionEnabled = YES;
    
    UIView * backview = [UIView new];
    backview.backgroundColor = UIColor.whiteColor;
    [self.contentView addSubview:backview];
    [DTKTool YJ:kwt(5) andView:backview];
    [backview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);
        make.bottom.right.offset(kwt(-10));
        make.left.offset(kwt(10));
    }];
    
    
    UIImageView * icon = kimageView(@"task_assigner_defaul_avatar");
    self.icon = icon;
    [backview addSubview:icon];
    [DTKTool YJ:kwt(27) andView:icon];
    [icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(kwt(54));
        make.left.top.offset(kwt(12));
    }];
    
    UILabel * realName = [DTKTool labelWithText:@"--" andFont:kCFont(19) andTextColor:KcolorHex(@"#222222")];
    self.realName = realName;
    [backview addSubview:realName];
    [realName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(77));
        make.top.offset(kwt(15));
        make.height.offset(kwt(19));
    }];
    
    UIView * zxview = [UIView new];
    self.zxview = zxview;
    zxview.clipsToBounds = YES;
    zxview.backgroundColor = KcolorHex(@"#0967FF");
    [DTKTool YJ:kwt(3) andView:zxview];
    [backview addSubview:zxview];
    [zxview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(realName.mas_right).offset(kwt(12));
        make.centerY.equalTo(realName);
        make.height.offset(kwt(18));
    }];
    MJWeakSelf
    UIView * SQview = [UIView new];
    SQview.addClickBlock(^{
        if(weakSelf.openSQBlock){
            if(weakSelf.model.ifAuthorize){//授权
                weakSelf.SQImg.image = [UIImage imageNamed:@"red_pull-down"];
            } else {
                weakSelf.SQImg.image = [UIImage imageNamed:@"gray_pull-down"];
            }
            weakSelf.openSQBlock(weakSelf.SQview,weakSelf.model);
        }
    });
    self.SQview = SQview;
    SQview.backgroundColor = KcolorHex(@"#F3F3F3");
    [DTKTool YJBK:kwt(3)andView:SQview andWidth:0.5 andColor:KcolorHex(@"#C8C8C8")];
    [backview addSubview:SQview];
    [SQview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(12));
        make.right.offset(kwt(-12));
        make.width.offset(kwt(63));
        make.height.offset(kwt(22));
    }];
    
    
    UILabel * SQLab = [DTKTool labelWithText:@"未授权" andFont:kCFont(12) andTextColor:KcolorHex(@"#7D7D7D")];
    self.SQLab = SQLab;
    [SQview addSubview:SQLab];
    [SQLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(5));
        make.centerY.offset(0);
    }];
    
    UIImageView * SQImg = kimageView(@"gray_pull-down1");
    self.SQImg = SQImg;
    [SQview addSubview:SQImg];
    [SQImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(kwt(10));
        make.right.offset(kwt(-5));
        make.centerY.offset(0);
    }];
    
    
    
    UIImageView * tempimg = kimageView(@"icon_crown");
    [zxview addSubview:tempimg];
    [tempimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(4));
        make.centerY.offset(0);
        make.height.width.offset(kwt(12));
    }];
    
    UILabel * templab1 = [DTKTool labelWithText:@"专属专家" andFont:kFont(14) andTextColor:UIColor.whiteColor];
    [zxview addSubview:templab1];
    [templab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.left.offset(kwt(17));
        make.right.offset(kwt(-4));

    }];
    
    
    UILabel * institution = [DTKTool labelWithText:@"--" andFont:kFont(16) andTextColor:KcolorHex(@"#7D7D7D")];
    self.institution = institution;
    institution.numberOfLines = 0;
    [backview addSubview:institution];
    [institution mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(77));
        make.top.offset(kwt(44));
        make.width.offset(kwt(265));
    }];
    
    UILabel * speciality = [DTKTool labelWithText:@"--" andFont:kFont(16) andTextColor:KcolorHex(@"#222222")];
    self.speciality = speciality;
    speciality.numberOfLines = 0;
    [backview addSubview:speciality];
    [speciality mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(77));
        make.top.equalTo(institution.mas_bottom).offset(kwt(10));
        make.width.offset(kwt(265));
    }];
    
    UIView * view = [UIView new];
    [backview addSubview:view];
    [DTKTool YJBK:kwt(7) andView:view andWidth:0.5 andColor:KcolorHex(@"#DFF2F9")];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(77));
        make.bottom.offset(kwt(-12));
        make.right.offset(kwt(-12));
        make.height.offset(kwt(35));
    }];
    
    UILabel * templab = [DTKTool labelWithText:@"点击数: " andFont:kFont(14) andTextColor:KcolorHex(@"#7D7D7D")];
    [view addSubview:templab];
    [templab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(6));
        make.centerY.offset(0);
    }];
    UILabel * callCount = [DTKTool labelWithText:@"-" andFont:kFont(14) andTextColor:KcolorHex(@"#7D7D7D")];
    self.callCount = callCount;
    [view addSubview:callCount];
    [callCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(templab.mas_right);
        make.centerY.offset(0);
    }];
    
    UIView * phoneview = [UIView new];
    phoneview.addClickBlock(^{
        if(weakSelf.openPhoneBlock){
            weakSelf.openPhoneBlock(weakSelf.model);
        }
    });
    phoneview.backgroundColor = KcolorHex(@"#ECF9FF");
    [view addSubview:phoneview];
    [DTKTool YJ:kwt(7) andView:phoneview];
    [phoneview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(104));
        make.top.offset(kwt(2));
        make.bottom.right.offset(kwt(-2));
    }];
    
    UIImageView * phoneimg = kimageView(@"telephone_consultation");
    [phoneview addSubview:phoneimg];
    [phoneimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(32));
        make.centerY.offset(0);
        make.width.height.offset(kwt(22));
    }];
    
    UILabel * templab2 = [DTKTool labelWithText:@"电话咨询" andFont:kCFont(16) andTextColor:KcolorHex(@"#00C0FF")];
    [phoneview addSubview:templab2];
    [templab2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(64));
        make.centerY.offset(0);
    }];
}

- (void)setModel:(YTExpertModel *)model{
    _model = model;
    [self.icon LZsetImageWithImagePath:model.imgUrl placeholderImage:[UIImage imageNamed:@"task_assigner_defaul_avatar"]];
    self.zxview.hidden = !model.ifExclusive;
    self.realName.text = model.realName;
    self.institution.text = model.institution;
    [self.institution mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.offset(model.institutionH);
    }];
    self.speciality.text = model.speciality;
    [self.speciality mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.offset(model.specialityH);
    }];
    self.callCount.text = [NSString stringWithFormat:@"%lu", model.callCount];
    if(model.callCount > 10000){
        self.callCount.text = [NSString stringWithFormat: @"%f万+", floor(model.callCount/10000.0) ];;
    }
    
    if(model.ifAuthorize){//授权
        [DTKTool YJBK:kwt(3)andView:self.SQview andWidth:0.5 andColor:KcolorHex(@"#EA4C3E")];
        self.SQview.backgroundColor = UIColor.whiteColor;
        self.SQLab.text = @"已授权";
        self.SQLab.textColor = KcolorHex(@"EA4C3E");
        self.SQImg.image = [UIImage imageNamed:@"red_pull-down1"];
    } else {
        [DTKTool YJBK:kwt(3)andView:self.SQview andWidth:0.5 andColor:KcolorHex(@"#C8C8C8")];
        self.SQview.backgroundColor = KcolorHex(@"#F3F3F3");
        self.SQLab.text = @"未授权";
        self.SQLab.textColor = KcolorHex(@"#7D7D7D");
        self.SQImg.image = [UIImage imageNamed:@"gray_pull-down1"];
    }
    
}

@end
